<div class="auction_help">
	<dl>
		<dt><strong>如何出价赢得竞拍？</strong></dt>
		<dd class="i i-1">提交团购网站成为团购站会员</dd>
		<dd class="j"></dd>
		<dd class="i i-2">充值积分，选择竞拍巧出价</dd>
		<dd class="j"></dd>
		<dd class="i i-3">赢得竞拍即支付</dd>
	</dl>
</div>
<div class="blank9"></div>
<dl class="auction_hot">
	<dt><strong>今日热拍</strong></dt>
	<dd>
		<!--{eval $auction_ids = array();}-->
		<!--{if count($auction_hot_list) > 0}-->
		<ul>
			<!--{eval $index = 0;}-->
			<!--{loop $auction_hot_list $auction_item}-->
			<!--{if ($index % 3) == 0 && $index > 2}-->
			<li class="jg"></li>
			<!--{/if}-->
			<li id="auction_{$auction_item[id]}">
				<div class="name"><a href="$auction_item[url]" target="_blank" title="$auction_item[name]">$auction_item[name]</a></div>
				<div class="img">
					<a href="$auction_item[url]" target="_blank"><img src="$auction_item[img]" alt="$auction_item[name]" /></a>
				</div>
				<!--{if $auction_item['end_time_js'] == '0'}-->
				<div class="time">长期有效</div>
				<!--{else}-->
				<div class="time endtime" endTime="$auction_item[end_time_js]">--:--:--</div>
				<!--{/if}-->
				<!--{if $auction_item['buyout_price'] > 0}-->
				<table class="pu" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td>当前价：</td>
						<td class="auction_price" bidPrice="$auction_item[base_price]"><span>$auction_item[base_price_format]</span></td>
						<td>&nbsp;&nbsp;</td>
						<td>一口价：</td>
						<td class="buyout_price"><span>$auction_item[buyout_price_format]</span></td>
					</tr>
				</table>
				<div class="auction_user user_name" id="bid_user_name">
					出价人：<span>---</span>
				</div>
				<table border="0" cellpadding="0" cellspacing="0" class="auction_btns">
					<tr>
						<td class="auction_btn"><a auctionID="$auction_item[id]" {if intval($_FANWE['uid']) > 0}href="javascript:;" class="bid"{else}href="{u user/login}" class="login"{/if}></a></td>
						<td>&nbsp;&nbsp;</td>
						<td class="buyout_btn"><a auctionID="$auction_item[id]" {if intval($_FANWE['uid']) > 0}href="javascript:;" class="bid"{else}href="{u user/login}" class="login"{/if}></a></td>
					</tr>
				</table>
				<!--{else}-->
				<table class="pu" border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td>当前价：</td>
						<td class="auction_price" bidPrice="$auction_item[base_price]"><span>$auction_item[base_price_format]</span></td>
					</tr>
					<tr class="auction_user">
						<td>出价人：</td>
						<td><span>---</span></td>
					</tr>
				</table>
				<div class="auction_btn">
					<a auctionID="$auction_item[id]" {if intval($_FANWE['uid']) > 0}href="javascript:;" class="bid"{else}href="{u user/login}" class="login"{/if}></a>
				</div>
				<!--{/if}-->
				<div class="auction_success">
					<a href="$auction_item[url]" target="_blank"></a>
				</div>
			</li>
			<!--{eval $index++;$auction_ids[]=$auction_item['id'];}-->
			<!--{/loop}-->
		</ul>
		<!--{else}-->
		<div class="empty">暂无数据</div>
		<!--{/if}-->
		<div class="blank9"></div>
	</dd>
</dl>
<div class="blank9"></div>
<dl class="auction_list">
	<dt><strong>正在竞拍</strong></dt>
	<dd>
		<!--{if count($auction_list) > 0}-->
		<ul>
			<!--{loop $auction_list $auction_item}-->
			<li id="auction_{$auction_item[id]}">
				<div class="img">
					<a href="$auction_item[url]" target="_blank"><img src="$auction_item[img]" alt="$auction_item[name]" /></a>
				</div>
				<div class="info">
					<div class="name"><a href="$auction_item[url]" target="_blank" title="$auction_item[name]">$auction_item[name]</a></div>
					<table class="price" border="0" cellpadding="0" cellspacing="0" align="left">
						<tr>
							<td>起拍价：</td>
							<td><span>$auction_item[base_price_format]</span></td>
							<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
							<td>当前价：</td>
							<td class="auction_price" bidPrice="$auction_item[base_price]"><span>$auction_item[base_price_format]</span></td>
							<!--{if $auction_item['buyout_price'] > 0}-->
							<td>&nbsp;&nbsp;&nbsp;&nbsp;</td>
							<td>一口价：</td>
							<td class="buyout_price"><span>$auction_item[buyout_price_format]</span></td>
							<!--{/if}-->
						</tr>
					</table>
					<div class="auction_user">出价人：<span>---</span></div>
				</div>
				<!--{if $auction_item['end_time_js'] == '0'}-->
				<div class="time">长期有效</div>
				<!--{else}-->
				<div class="time endtime" endTime="$auction_item[end_time_js]">--:--:--</div>
				<!--{/if}-->
				<!--{if $auction_item['buyout_price'] > 0}-->
				<div class="auction_btns">
					<div class="auction_btn"><a auctionID="$auction_item[id]" {if intval($_FANWE['uid']) > 0}href="javascript:;" class="bid"{else}href="{u user/login}" class="login"{/if}></a></div>
					<div class="buyout_btn"><a auctionID="$auction_item[id]" {if intval($_FANWE['uid']) > 0}href="javascript:;" class="bid"{else}href="{u user/login}" class="login"{/if}></a></div>
				</div>
				<!--{else}-->
				<div class="auction_btn">
					<a auctionID="$auction_item[id]" {if intval($_FANWE['uid']) > 0}href="javascript:;" class="bid"{else}href="{u user/login}" class="login"{/if}></a>
				</div>
				<!--{/if}-->
				<div class="auction_success">
					<a href="$auction_item[url]" target="_blank"></a>
				</div>
			</li>
			<!--{eval $auction_ids[]=$auction_item['id'];}-->
			<!--{/loop}-->
		</ul>
		<!--{else}-->
		<div class="empty">暂无数据</div>
		<!--{/if}-->
		<div class="blank9"></div>
	</dd>
</dl>
<div class="blank9"></div>
<script type="text/javascript">
<!--{if count($auction_ids) > 0}-->
var ids = "{echo implode(',',$auction_ids)}";
var idArr = ids.split(",");
<!--{else}-->
var ids = "";
<!--{/if}-->
var auctionsTimeOut;
var activeTime;
var isActive = true;

jQuery(function($){
	if(ids != "")
		getAuctions();
		
	$(".auction_btn a.bid").click(function(){
		var id = this.getAttribute("auctionID");
		auctionBid(id,0);
	});
	
	$(".buyout_btn a.bid").click(function(){
		var id = this.getAttribute("auctionID");
		auctionBid(id,1);
	});
	
	$(".buyout_btn a.bid").click(function(){
		var id = this.getAttribute("auctionID");
		auctionBid(id,1);
	});
	
	$("body").mousemove(function(){
		var date = new Date();
		activeTime = date.getTime();
	});
	
	var date = new Date();
	activeTime = date.getTime();
	updateAuctionTime();
});

function getAuctions()
{
	if(!isActive)
		return;
	
	$.ajax({
		type: "GET",
		cache:false,
		url: SITE_PATH + "/services/auction.php",
		data: {"action":"get_auctions","ids":ids},
		dataType:'json',
		success: function(data){
			var i = 0;
			var count = idArr.length;
			var id,auction,auctionLI,price,bidPrice;
			for(i;i<count;i++)
			{
				id = idArr[i];
				try
				{
					auctionLI = $('#auction_'+id);
					auction = data['auction_'+id];
					if(auction.bid)
					{
						price = parseFloat($(".auction_price",auctionLI).get(0).getAttribute("bidPrice"))
						
						bidPrice = parseFloat(auction.bid.price);
						if(bidPrice != price)
						{
							$(".auction_price span",auctionLI).css({"backgroundColor":"#ff5151"}).html('¥'+bidPrice);
							$(".auction_price span",auctionLI).stop(true,true).animate({
								backgroundColor:'#fff'
							}, 500);
							$(".auction_price",auctionLI).get(0).setAttribute("bidPrice",bidPrice);
						}
						
						$(".auction_user span",auctionLI).html(auction.bid.username);
					}
					
					if(auction.auction_status == 1)
					{
						$(".auction_btns,.auction_btn",auctionLI).hide();
						$(".auction_success",auctionLI).show();
						if(!auction.bid)
							$(".auction_success",auctionLI).addClass("auction_end");
						
						$(".time",auctionLI).removeClass("endtime").addClass("successtime").css({"color":"#ccc"}).html("--:--:--");
					}
					
					if($(".endtime",auctionLI).length > 0)
						$(".endtime",auctionLI).get(0).setAttribute("endTime",auction.end_time_js);
				}
				catch(e){};
			}
			auctionsTimeOut = setTimeout("getAuctions()",1000);
		},
		error:function(r, t, e){
			alert('连接服务器失败，请刷新页面或联系管理员！');
		}
	});
}

function auctionBid(id,isBuyout)
{
	clearTimeout(auctionsTimeOut);
	$.ajax({
		type: "GET",
		cache:false,
		url: SITE_PATH + "/services/auction.php",
		data: {"action":"bid","id":id,"is_buyout":isBuyout},
		dataType:'json',
		success: function(data){
			if(data.is_error && data.message != '')
			{
				$.showWindow({"title":"竞拍提示","html":'<div class="auction_error"><p>'+ data.message +'</p><a href="javascript:;" class="auction_close">关 闭</a></div>'});
				$(".auction_error a").click(function(){
					$("#fwindow .fwindow_close").click();
				});
			}
			getAuctions();
		},
		error:function(r, t, e){
			alert('连接服务器失败，请刷新页面或联系管理员！');
		}
	});
}

function auctionActive()
{
	var activeDate = new Date();
	activeTime = activeDate.getTime();
	isActive = true;
	updateAuctionTime();
	getAuctions();
}

function updateAuctionTime()
{
	var date = new Date();
	var time = date.getTime();
	
	if(time - activeTime > 600000)
		isActive = false;
	
	if(!isActive)
	{
		$.showWindow({"title":"竞拍提示","html":'<div class="auction_active"><p>您超过10分钟未进行任何操作。<br/>"继续"或关闭窗口则会激活。</p><a href="javascript:;">继 续</a></div>',closeFun:auctionActive});
		
		$(".auction_active a").click(function(){
			$("#fwindow .fwindow_close").click();
		});
		
		return false;
	}
	
	$(".endtime").each(function(i){
		var endDate =new Date(this.getAttribute("endTime"));
		var endTime = endDate.getTime();
		var ms = Math.floor(Math.floor((endTime - time) % 1000) /100);
		var lag = Math.floor((endTime - time) / 1000);
		if(lag > 0)
		{
			var second = Math.floor(lag % 60);
			var minite = Math.floor((lag / 60) % 60);
			var hour = Math.floor((lag / 3600) % 24);
			var day = Math.floor((lag / 3600) / 24);
			hour += day * 24;
			if(lag <= 10)
			{
				$(this).css({"color":"red"});
				$(this).html((hour > 9 ? hour : '0' + hour)+":"+(minite > 9 ? minite : '0' + minite)+":"+ (second > 9 ? second : '0' + second +"."+ ms));
			}
			else
				$(this).html((hour > 9 ? hour : '0' + hour)+":"+(minite > 9 ? minite : '0' + minite)+":"+ (second > 9 ? second : '0' + second));
		}
		else
			$(this).html("00:00:00");
	});
	
	setTimeout("updateAuctionTime()",100);
}
</script>